package com.amrit;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringOccurance {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		StringOccurance.checkNoOfOccurence("I am in India", "in");
		
	}

	public static void checkNoOfOccurence(String str, String search) {
		String stArr[] = str.split(" ");
		//Pattern pattern = Pattern.compile(".*" + search + ".*",Pattern.CASE_INSENSITIVE);
		Pattern pattern = Pattern.compile(".*" + search + ".*"); // case sensitive search
		int count = 0;
		for (int i = 0; i < stArr.length; i++) {
			Matcher matcher = pattern.matcher(stArr[i]);
			if (matcher.matches()) {
				count++;
			}
		}
		System.out.println("Search String is:- " + search + "\t Count is:- " + count);
	}

}
